const app= getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    ask:0,
    phone:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
      let that  = this;
    var deviceInfo = wx.getDeviceInfo(); 
    var series_id = options.series_id;
   // series_id =5;
    this.getSeries(series_id)


    let d = app.globalData;
      that.setData({
          width:d.windowWidth,
          height:d.windowHeight,
          statusBarHeight:d.statusBarHeight,
          navHeight:d.navHeight,
          marginTop:d.navTitleTop,
          bottom:d.bottom,
          domain:d.domain,
         imgUrl:d.imgUrl,
          platform:deviceInfo.platform
        })
  },
  goBack(e){
    const pages = getCurrentPages();
      const prevPage = pages[pages.length - 2]; // 获取上一个页面实例
      console.log(prevPage);
      wx.navigateBack();
      //wx.navigateBack();
  },
getSeries(series_id){
    let that = this;
    wx.request({
      url: app.globalData.domain+'/wechat/series/getSeriesParam',
      data:{series_id:series_id},
      success:res=>{
            let d = res.data;
            that.setData({
                series:d.series,
                list:d.list
            })
      }
    })
},
hideAsk(){
    this.setData({
        ask:0
    })
},
showAsk(){
    let that = this;
    var open = wx.getStorageSync('open');
    console.log(open);
    if(open.phone!=''){
        this.setData({ phone:open.phone})
       
    }
    this.setData({
        ask:1
    })
    const query = wx.createSelectorQuery();
  query.select('#pop-ask').boundingClientRect(function(res) {
    that.setData({
        popHeight:res.top
    })
  }).exec();
},
gotoAsk(){
    let d = this.data;
    let that = this;
    var open = wx.getStorageSync('open');
   var phone = d.phone;
   var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
   var series = d.series;
   if (phone.length == 0) {
       wx.showToast({
           title: '请输入手机号!',
           icon: 'success',
           duration: 1500
       });
       return false;
   }
   if (phone.length != 11) {
       wx.showToast({
           title: '手机号长度有误!',
           icon: 'success',
           duration: 1500
       });
       return false;
   }
   if (!myreg.test(phone)) {
       wx.showToast({
           title: '手机号有误!',
           icon: 'success',
           duration: 1500
       });
       return false;
   }
   wx.request({
    url: app.globalData.domain+'/wechat/series/ask',
    data:{series_id:series.id,type:2,phone:phone,open_id:open.id,user_id:open.user_id},
    success:res=>{
          let d = res.data;
          that.setData({
              ask:0
          })
          app.showModal(d.msg,'#','#')
    }
  })

},
input(e){
    var value = e.detail.value;
    this.setData({
        phone:value
    })

},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    var open = wx.getStorageSync('open');
    this.setData({
        open:open
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})